// 作业路由
const express = require('express');
const router = express.Router();
const HomeworkController = require('../controllers/homeworkController');
const { authMiddleware, teacherMiddleware } = require('../utils/authMiddleware');
const { singleFileUpload } = require('../utils/uploadConfig');

/**
 * 作业路由
 * 定义作业相关的API端点
 */

// 获取作业列表（学生和教师都可以查看）
router.get('/', authMiddleware, HomeworkController.getHomeworkList);

// 获取学生可提交的作业 - 这个路由必须在/:homeworkId之前定义
router.get('/available', authMiddleware, HomeworkController.getAvailableHomeworks);

// 获取单个作业详情
router.get('/:homeworkId', authMiddleware, HomeworkController.getHomeworkById);

// 教师专用路由（管理作业）
router.post('/', authMiddleware, teacherMiddleware, singleFileUpload('attachment'), HomeworkController.createHomework);
router.put('/:homeworkId', authMiddleware, teacherMiddleware, singleFileUpload('attachment'), HomeworkController.updateHomework);
router.delete('/:homeworkId', authMiddleware, teacherMiddleware, HomeworkController.deleteHomework);

module.exports = router;